//
//  RenrenLoginViewController.h
//  huipai_3
//
//  Created by tan xi on 11-9-9.
//  Copyright 2011年 __MyCompanyName__. All rights reserved.
//


@protocol RRViewControllerDelegate;

@interface RenrenLoginViewController : UIViewController 
<UIWebViewDelegate>{
    id<RRViewControllerDelegate> _delegate;
    NSMutableDictionary *_params;
    NSString * _serverURL;
    NSURL* _loadingURL;
    UIWebView* _webView;
    UIActivityIndicatorView* _spinner;
    UIImageView* _iconView;
    UIDeviceOrientation _orientation;
    BOOL _showingKeyboard;
    UIView* _modalBackgroundView;
}

@property(nonatomic,assign) id<RRViewControllerDelegate> delegate;

@property(nonatomic, retain) NSMutableDictionary* params;

- (NSString *) getStringFromUrl: (NSString*) url needle:(NSString *) needle;

- (id)initWithURL: (NSString *) loadingURL
           params: (NSMutableDictionary *) params
         delegate: (id <RRViewControllerDelegate>) delegate;

- (NSDictionary*)parseURLParams:(NSString *)query;

-(void) errormsg:(NSString*) errorReason;

- (void)load;

- (void)loadURL:(NSString*)url
            get:(NSDictionary*)getParams;

//隐藏视图并通知委托成功或者取消
- (void)dismissWithSuccess:(BOOL)success animated:(BOOL)animated;

//隐藏视图并通知委托出现错误
- (void)dismissWithError:(NSError*)error animated:(BOOL)animated;


- (void)dialogDidSucceed:(NSURL *)url;


- (void)dialogDidCancel:(NSURL *)url;

@end

@protocol RRViewControllerDelegate <NSObject>

@optional

/**
 * dialog 成功调用.
 */
- (void)loginViewDidComplete:(RenrenLoginViewController *)dialog;

/**
 * 
 * 当dialog成功调用返回一个url时调用
 */
- (void)loginViewCompleteWithUrl:(NSURL *)url;

/**
 * 
 * 当dialog 让用户取消时调用
 */
- (void)loginViewDidNotCompleteWithUrl:(NSURL *)url;

- (void)loginViewDidNotComplete:(RenrenLoginViewController *)dialog;

/**
 * 当dialog 加载时遇到错误时调用.
 */
- (void)loginView:(RenrenLoginViewController*)dialog didFailWithError:(NSError *)error;

- (BOOL)loginView:(RenrenLoginViewController*)dialog shouldOpenURLInExternalBrowser:(NSURL *)url;

- (void)widgetloginViewCompleteWithDict:(NSDictionary*)params;

/**
 * dialog登录授权成功执行
 */
- (void)rrLoginViewLogin:(NSString*)token expirationDate:(NSDate*)expirationDate;
/**
 * 取消登录时执行
 */
- (void)rrLoginViewNotLogin:(BOOL)cancelled;


@end
